﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinanSoft.Entities;
using FinanSoft.DataLayer;
using FinanSoft.Utilities;

namespace FinanSoft.BusinessLayer
{
    class OrdenCompraManager
    {
        #region Fields
        private bool _IsError;
        private String _ErrorMessage;
        private bool _definiteError;
        private static OrdenCompraManager _instance;
        private List<ArticuloDocumento> _articleDocument;
        #endregion

        #region Propiedades
        public bool IsError
        {
            get
            {
                bool temp = _IsError;
                _IsError = false;
                return temp;
            }
        }

        public String ErrorMessage
        {
            get
            {
                String temp = _ErrorMessage;
                _IsError = false;
                _ErrorMessage = "";
                return temp;
            }
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Constructor privado de la clase para permitir la implementacion del patron singleton
        /// </summary>
        private OrdenCompraManager()
        {
            _IsError = false;
            _ErrorMessage = "";
            _articleDocument = OrdenCompraDataManager.GetInstance().GetArticleDocuments();

            if (_articleDocument == null)
            {
                _IsError = true;
                _ErrorMessage = Constants.ERROR_ARTICLE_DOCUMENT_READING;
            } 
            else
            {
                _IsError = false;
            }

        }
        #endregion  

        #region Methods
        /// <summary>
        /// Metodo que obtienen la instancia existente de la clase. Si esta aun no ha sido instanciada, la instancia.
        /// </summary>
        public static OrdenCompraManager GetInstance()
        {
            if (_instance == null)
                _instance = new OrdenCompraManager();
            return _instance;
        }

        
         

        /// <summary>
        /// Metodo que se encarga de registrar un nuevo articulo documento
        /// </summary>
        /// <param name="newStore">articulo documento a registrar</param>
        /// <returns>Valor de verdad correspondiente al exito del registro</returns>
        public bool RegisterArticleDocument(ArticuloDocumento newArticleDocument)
        {
            int noErrorDB;

            noErrorDB = OrdenCompraDataManager.GetInstance().RegisterArticleDocument(newArticleDocument);
            if (noErrorDB == -1)
            {
                _IsError = true;
                _ErrorMessage = Constants.ERROR_NEW_ARTICLE_DOCUMENT_FAILED;
                return false;
            }

            newArticleDocument.IdDocumentoContable = noErrorDB;
            _articleDocument.Add(newArticleDocument);
            return true;
 
        }


        /// <summary>
        /// Metodo que retorna la lista de bodegas registradas en el sistema
        /// </summary>
        /// <returns></returns>
        public List<ArticuloDocumento> GetArticleDocuments()
        {
            if (_articleDocument == null)
            {
                _IsError = true;
                _ErrorMessage = Constants.ERROR_ARTICLE_DOCUMENT_READING;
            }

            return _articleDocument;
        }

        


        #endregion

    }
}
